import axios from '@/libs/axios1'
import { escape2Html } from '@/libs/utils'
let jsonHeaders = {
	'content-type': 'application/json;charset=UTF-8'
}

//根据名称和字典类型id查询字典项
export const allDirection = (params = {dictTypeID:''}) => {
	return axios({
		url: `/dictionaries/dictEntrys/selDictTypeAndDictEntitpInfo?dictTypeID=${params.dictTypeID}`,
		method: 'post',
		data:{},
		headers: jsonHeaders
	})
}

// 根据字典类型查询字典项
export const experType = (type = 'newDirectionType', isFilter = true) => {
	return new Promise(resolve => {
		axios({
			url: `/dictionaries/dictTypes/selDictTypeAndDictEntitpInfo`,
			method: 'get',
			params:{
				dictTypeID:type
			},
			headers: jsonHeaders,
		}).then(res => {
			let { code, attribute } = res
			if (code === 1) {
				attribute = attribute.attribute
				attribute.forEach(item => {
					if (isFilter) {
                        item.dictEntryList = item.dictEntryList.filter(subItem => {
                            if (subItem.flag === 1) {
                                subItem.dictname = escape2Html(subItem.dictname)
							    subItem.dictid = escape2Html(subItem.dictid)
                                return subItem
                            }
                        })
					} else {
						item.dictEntryList.forEach(subItem => {
							subItem.dictname = escape2Html(subItem.dictname)
							subItem.dictid = escape2Html(subItem.dictid)
						})
					}
				})
			}
			resolve(res)
		})
	})
}

export const getDictInfoByName = params => {
	return axios({
		url: `/dictionaries/sysConf/getInfoByName`,
		method: 'get',
		params: params,
		headers: jsonHeaders
	})
}

export const getSysConfigList = params =>{
	return axios({
		url: `/dictionaries/sysConf/list`,
		method: 'get',
		params: params,
		headers: jsonHeaders
	})
}

//获取服务器时间
export const getServerTime = questionObj => {
  return axios({
    url: `/dictionaries/sysConf/currentTime`,
    method: 'get',
    headers: jsonHeaders
  })
}

// 获取标签
export const getSelLabelType = (id='labels') => {
	return axios({
		url: `/dictionaries/dictEntrys/selLabelType/${id}`,
		method: 'get',
		headers: jsonHeaders
	})
}

// 添加标签
export const dictEntrysSave = (name) => {
	return axios({
		url: `/dictionaries/dictEntrys/save/${name}`,
		method: 'post',
		headers: jsonHeaders
	})
}
// 添加标签数组
export const dictEntrysSaveBatch = (data) => {
	return axios({
		url: `/dictionaries/dictEntrys/saveBatch`,
		method: 'post',
		data,
		headers: jsonHeaders
	})
}

// 获取标签分页 暂时没使用
export const getSelLabels = (params) => {
	return axios({
		url: `/dictionaries/dictEntrys/selLabelTypePage/${params.dictTypeID}`,
		method: 'get',
		params,
		headers: jsonHeaders
	})
}